function createDialogHeader(){
	var html='<div id="dialog" style="display:none;">';
	html+='<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0">';
		html+='<tbody>';
			//标题行
			html+='<tr style="cursor:move;">';
				//标题左上角圆角
				html+='<td class="leftTop">';
				html+='</td>';
				//标题和关闭按钮
				html+='<td class="midTop">';
					html+='<div class="DialogTitle">';
						html+='<img align="absmiddle" src="../../images/icons/icon_dialog.gif">&nbsp;';
						html+='<span>窗口</span>';
					html+='</div>';
					html+='<div class="DialogClose"></div>';
				html+=' </td>';
				//标题右上角圆角
				html+='<td class="rightTop">';
				html+='</td>';
			html+='</tr>';
			
			//页面区域
			html+='<tr>';
				//左边框
				html+='<td class="leftDialogBorder">';
				html+='</td>';
				//内容区域
				html+='<td valign="top" align="center">';
					html+='<table width="100%" height="100%" cellspacing="0" cellpadding="0" border="0" bgcolor="#FFFFFF">';
						html+='<tbody>';
	return html;
}
function createDialogBottom(){
	var html='</tbody>';
	html+='</table>';
	html+='</td>';
	//右边框
	html+='<td class="rightDialogBorder"></td>';
	html+='</tr>';
	
	//底部边框
	html+='<tr>';
	html+='<td class="leftBottom"></td>';
	html+='<td class="midBottom"></td>';
	html+='<td class="rightBottom"></td>';
	html+='</tr>';
	html+='</tbody>';
	html+='</table>';
	html+='</div>';
	return html;
}

function createDialogHtml(dialogType){
	var html=createDialogHeader();
	//Dialog加载的页面
	html+='<tr>';
		html+='<td valign="top" align="center">';
			html+='<iframe id="dialogIframe" class="frameDialog" src=""></iframe>';
		html+='</td>';
	html+='</tr>';
	//按钮区域
	html+='<tr id="_ButtonRow_Diag1" drag="false">';
		html+='<td height="36">';
			html+=' <div style="text-align:right; border-top:#dadee5 1px solid; padding:8px 20px; background-color:#f6f6f6;" id="_DialogButtons_Diag1">';
				html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="confirmBtn" value="确 定"></a>&nbsp;';
				html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="cancelBtn" value="取 消"></a>';
			html+='</div>';
		html+='</td>';
	html+='</tr>';
		
	html+=createDialogBottom();
	return html;
};
function createConfirmHtml(msg){
	var html=createDialogHeader();
	//Dialog加载的页面
	html+='<tr>';
		html+='<td valign="top" align="center">';
			html+='<div>';
				html+='<table height="100%" cellspacing="0" cellpadding="10" border="0" align="center">';
					html+='<tbody>';
						html+='<tr>';
							html+='<td align="right">';
								html+='<img width="34" height="34" align="absmiddle" src="../../images/icons/icon_query.gif" id="Icon">';
							html+='</td>';
							html+='<td align="left" style="font-size: 9pt" id="Message">';
							html+=msg;
							html+='</td>';
						html+='</tr>';
					html+='</tbody>';
				html+='</table>';
			html+='</div>';
		html+='</td>';
	html+='</tr>';
	//按钮区域
	html+='<tr id="_ButtonRow_Diag1" drag="false">';
	html+='<td height="36">';
	html+=' <div style="text-align:center; border-top:#dadee5 1px solid; padding:8px 20px; background-color:#f6f6f6;" id="_DialogButtons_Diag1">';
	html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="confirmBtn" value="确 定"></a>&nbsp;';
	html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="cancelBtn" value="取 消"></a>';
	html+='</div>';
	html+='</td>';
	html+='</tr>';
	
	html+=createDialogBottom();
	return html;
}
function createPromptHtml(msg){
	var html=createDialogHeader();
	//Dialog加载的页面
	html+='<tr>';
		html+='<td valign="top" align="center">';
			html+='<div>';
				html+='<table height="100%" cellspacing="0" cellpadding="10" border="0" align="center">';
					html+='<tbody>';
						html+='<tr>';
							html+='<td>';
								html+='<input id="promptInput"/>';
							html+='</td>';
						html+='</tr>';
					html+='</tbody>';
				html+='</table>';
			html+='</div>';
		html+='</td>';
	html+='</tr>';
	//按钮区域
	html+='<tr id="_ButtonRow_Diag1" drag="false">';
	html+='<td height="36">';
	html+=' <div style="text-align:center; border-top:#dadee5 1px solid; padding:8px 20px; background-color:#f6f6f6;" id="_DialogButtons_Diag1">';
	html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="confirmBtn" value="确 定"></a>&nbsp;';
	html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="cancelBtn" value="取 消"></a>';
	html+='</div>';
	html+='</td>';
	html+='</tr>';
	
	html+=createDialogBottom();
	return html;
}
function createAlertHtml(msg){
	var html=createDialogHeader();
	//Dialog加载的页面
	html+='<tr>';
	html+='<td valign="top" align="center">';
	html+='<div>';
	html+='<table height="100%" cellspacing="0" cellpadding="10" border="0" align="center">';
	html+='<tbody>';
	html+='<tr>';
	html+='<td align="right">';
	html+='<img width="34" height="34" align="absmiddle" src="../../images/icons/icon_alert.gif">';
	html+='</td>';
	html+='<td align="left" style="font-size: 9pt" id="Message">';
	html+=msg;
	html+='</td>';
	html+='</tr>';
	html+='</tbody>';
	html+='</table>';
	html+='</div>';
	html+='</td>';
	html+='</tr>';
	//按钮区域
	html+='<tr id="_ButtonRow_Diag1" drag="false">';
	html+='<td height="36">';
	html+=' <div style="text-align:center; border-top:#dadee5 1px solid; padding:8px 20px; background-color:#f6f6f6;" id="_DialogButtons_Diag1">';
	html+='<a tabindex="-1" hidefocus="true" class="zInputBtn" href="javascript:void(0);"><input type="button" class="inputButton" id="confirmBtn" value="确 定"></a>';
	html+='</div>';
	html+='</td>';
	html+='</tr>';
	
	html+=createDialogBottom();
	return html;
}

/*
 * params={
 * 'title':'test',
 * 'url':src,
 * frameSubmitType:iframe|gridSelect...,
 * 'path':path
 * width:650,
 * height:400,
 * btnSucFunc:function(){
 * window.location.reload();
 * }
 * }
 */
function createIframeDialog(params){
	var title='窗口';
	var frameSubmitType='form';
	var width=650;
	var height=400;
	var confirmBtn=true;
	var btnSucFunc=function(){
		  window.location.reload();
		 };
	if(params['title']!=undefined){
		title=params['title'];
	}
	if(params['frameSubmitType']!=undefined){
		frameSubmitType=params['frameSubmitType'];
	}
	if(params['width']!=undefined){
		width=params['width'];
	}
	if(params['height']!=undefined){
		height=params['height'];
	}
	if(params['btnSucFunc']!=undefined){
		btnSucFunc=params['btnSucFunc'];
	}
	if(params['confirmBtn']!=undefined){
		confirmBtn=params['confirmBtn'];
	}
	var url=params['url'];
	
	var dialogObj=$(createDialogHtml());
	dialogObj.appendTo($("body"));
	dialogObj.dialog({
		width:width,
		height:height,
		modal:true,
		open:function(){
			removeOldDialogBorder($(this).parent());
			if(url!=''){
				if(!confirmBtn){//如果不需要数据提交，则移除确定按钮
					dialogObj.find('#confirmBtn').parent().remove();
				}
				var TdWidth=$(this).find(".frameDialog").parent().width();
				var TdHeight=$(this).find(".frameDialog").parent().height();
				$(this).find(".frameDialog").css({height:TdHeight,width:TdWidth}).attr('src',url);//在窗口打开时设置iframe路径
				
			}else{
				$(this).find(".frameDialog").parent().html("test信息");
			}
		},
		close:function(){
			$(this).html('');//每次关闭必须清空iframe，否则会重复加载
		}
	});
	
	//取消按钮
	dialogObj.find('#cancelBtn').unbind('click').bind('click',function(){
		dialogObj.dialog("close");}
	);
	//设置标题
	dialogObj.find('.DialogTitle span').text(title);
	//设置拖拽事件
	dialogObj.find('.DialogTitle').bind('mousedown',function(){
		dialog.find(".ui-dialog-titlebar").drag();
	});
	//关闭按钮
	dialogObj.find('.DialogClose').hover(function(){
		$(this).toggleClass('DialogCloseHover');
	}).unbind('click').bind('click',function(){
		dialogObj.dialog("close");}
	);
	var waitingDiv='';//锁定屏幕DIV
	//确定按钮
	dialogObj.find('#confirmBtn').unbind('click').bind('click',function(){
		var iframeObj=$(document.getElementById('dialogIframe').contentDocument);//获取iframe的内容
		if(frameSubmitType=='form'){//弹出窗口是form，确认按钮提交form
			var formObj=iframeObj.find('form');
			var options = { 
			        success:showResponse,  // post-submit callback 
			        error:showError,
			        dataType:'json',        // 'xml', 'script', or 'json' (expected server response type) 
			        timeout:3000 
			    }; 
			formObj.die('submit').live('submit',function() {//必须得先die下提交事件，否则会造成重复提交
					//提交之前是否做特殊校验或者加上特殊参数，例如新增或编辑用户时需要勾选角色
					//此时可以将提交前需要执行的校验或其他操作写到iframe页面的窗口里，function beforeFormSubmitFunc(){alert('test');return false;}
					//beforeFormSubmitFunc该方法返回操作结果，true/false，true则允许提交，否则不提交
					var ibeforeFormSubmitFunc=document.getElementById('dialogIframe').contentWindow.beforeFormSubmitFunc;
					if(ibeforeFormSubmitFunc!=undefined){
						if(ibeforeFormSubmitFunc()){
							//锁定提交页面
							waitingDiv="<div id='dialogWaitingDiv' style='z-index:9999;display:none;background:#dddddd;opacity:0.5;position:absolute;top:0;left:0;margin-top:13px;margin-left:20px;'>";
							waitingDiv+="<center><span id='dialogWatingSpan'><img src='../../images/loadingGreen15px.gif'/>操作正在进行中，请稍后......</span></center></div>";
							$(waitingDiv).css({height:dialogObj.height()-10,width:dialogObj.width()-10}).appendTo(dialogObj).show().find('span').css({'position':'relative','top':(dialogObj.height()-$('#dialogWatingSpan').height())/2});
							$(this).ajaxSubmit(options); 
						}
					}else{
						//锁定提交页面
						waitingDiv="<div id='dialogWaitingDiv' style='z-index:9999;display:none;background:#dddddd;opacity:0.5;position:absolute;top:0;left:0;margin-top:13px;margin-left:20px;'>";
						waitingDiv+="<center><span id='dialogWatingSpan'><img src='../../images/loadingGreen15px.gif'/>操作正在进行中，请稍后......</span></center></div>";
						$(waitingDiv).css({height:dialogObj.height()-10,width:dialogObj.width()-10}).appendTo(dialogObj).show().find('span').css({'position':'relative','top':(dialogObj.height()-$('#dialogWatingSpan').height())/2});
						$(this).ajaxSubmit(options); 
					}
					return false; 
			    }); 
			formObj.submit();
		}else if(frameSubmitType=='gridSelect'){//弹出窗口是DataGrid选择列，确认按钮执行所选择的内容
			var dataGridObj=iframeObj.find('.dataGridTable');
			var ids=dataGridObj.jqGrid('getGridParam','selarrrow');
			var path=params['path']+ids;
			//锁定提交页面
			waitingDiv="<div id='dialogWaitingDiv' style='z-index:9999;display:none;background:#dddddd;opacity:0.5;position:absolute;top:0;left:0;margin-top:13px;margin-left:20px;'>";
			waitingDiv+="<center><span id='dialogWatingSpan'><img src='../../images/loadingGreen15px.gif'/>操作正在进行中，请稍后......</span></center></div>";
			$(waitingDiv).css({height:dialogObj.height()-10,width:dialogObj.width()-10}).appendTo(dialogObj).show().find('span').css({'position':'relative','top':(dialogObj.height()-$('#dialogWatingSpan').height())/2});
			$.ajax({
				type : "GET",
				url : path,
				dataType : "json",
				success : function(data) {
					//去掉锁定
					$('#dialogWaitingDiv').remove();
					waitingDiv='';
					if (data['status'] == 'ERROR') {
						createAlertDialog('提示信息',data['msg']);
					} else if (data['status'] == 'SUCCESS'){
						dialogObj.dialog("close");
						createAlertDialog('提示信息',data['msg'],function(){
							btnSucFunc();
						});
					}
				},
				error : function() {
					//去掉锁定
					$('#dialogWaitingDiv').remove();
					waitingDiv='';
					createAlertDialog('提示信息','网络繁忙,请稍后再试!');
				}
			});
		}
			
		
	});
	
	return dialogObj;
	
	function showResponse(data){
		//去掉锁定
		$('#dialogWaitingDiv').remove();
		waitingDiv='';
		if(data['status']=='SUCCESS'){
			dialogObj.dialog("close");
			createAlertDialog('提示信息',data['msg'],function(){
				btnSucFunc();
			});
		}else if(data['status']=='ERROR'){
			createAlertDialog('提示信息',data['msg']);
		}
	}
	function showError(data){
		//去掉锁定
		$('#dialogWaitingDiv').remove();
		waitingDiv='';
		createAlertDialog('提示信息','网络繁忙，请稍后再试!');
	}
	
}
function createConfirmDialog(title,msg,btnFunc,width,height){
	var dialogObj=$(createConfirmHtml(msg));
	dialogObj.appendTo($("body"));
	width=(width==undefined?300:width);
	height=(height==undefined?200:height);
	dialogObj.dialog({
		width:width,
		height:height,
		modal:true,
		open:function(){
			removeOldDialogBorder($(this).parent());
		},
		close:function(){
			$(this).html('');//每次关闭必须清空iframe，否则会重复加载
		}
	});
	
	//取消按钮
	dialogObj.find('#cancelBtn').unbind('click').bind('click',function(){
		dialogObj.dialog("close");}
	);
	//设置标题
	dialogObj.find('.DialogTitle span').text(title);
	//设置拖拽事件
	dialogObj.find('.DialogTitle').bind('mousedown',function(){
		dialog.find(".ui-dialog-titlebar").drag();
	});
	//关闭按钮
	dialogObj.find('.DialogClose').hover(function(){
		$(this).toggleClass('DialogCloseHover');
	}).unbind('click').bind('click',function(){
		dialogObj.dialog("close");}
	);
	
	//确定按钮
	dialogObj.find('#confirmBtn').unbind('click').bind('click',function(){
		dialogObj.dialog("close");
		if(btnFunc!=undefined&&btnFunc!=null){
			btnFunc();
		}
	});
	
	return dialogObj;
}

function createPromptDialog(title,type,selectObj,btnFunc,width,height){
	var dialogObj=$(createPromptHtml(title));
	dialogObj.appendTo($("body"));
	width=(width==undefined?280:width);
	height=(height==undefined?172:height);
	dialogObj.dialog({
		width:width,
		height:height,
		modal:true,
		open:function(){
			removeOldDialogBorder($(this).parent());
		},
		close:function(){
			$(this).html('');//每次关闭必须清空iframe，否则会重复加载
		}
	});
	
	//取消按钮
	dialogObj.find('#cancelBtn').unbind('click').bind('click',function(){
		dialogObj.dialog("close");
		selectObj.val($(selectObj.find("option")[0]).attr('value')).change();
	}
	);
	//设置标题
	dialogObj.find('.DialogTitle span').text(title);
	//设置拖拽事件
	dialogObj.find('.DialogTitle').bind('mousedown',function(){
		dialog.find(".ui-dialog-titlebar").drag();
	});
	//关闭按钮
	dialogObj.find('.DialogClose').hover(function(){
		$(this).toggleClass('DialogCloseHover');
	}).unbind('click').bind('click',function(){
		dialogObj.dialog("close");
		selectObj.val($(selectObj.find("option")[0]).attr('value')).change();
	}
	
	);
	
	//确定按钮
	dialogObj.find('#confirmBtn').unbind('click').bind('click',function(){
		var newValue=$("#promptInput").val();
		dialogObj.dialog("close");
		if(btnFunc!=undefined&&btnFunc!=null){
			btnFunc();
		}else{
			selectObj.append("<option value='"+type+"."+newValue+"'>"+newValue+"</option>");
			selectObj.val(type+"."+newValue).change();
		}
	});
	
	return dialogObj;
}

function createAlertDialog(title,msg,btnFunc,width,height){
	var dialogObj=$(createAlertHtml(msg));
	dialogObj.appendTo($("body"));
	width=(width==undefined?300:width);
	height=(height==undefined?200:height);
	dialogObj.dialog({
		width:width,
		height:height,
		modal:true,
		open:function(){
			removeOldDialogBorder($(this).parent());
		},
		close:function(){
			$(this).html('');//每次关闭必须清空iframe，否则会重复加载
		}
	});
	
	//设置标题
	dialogObj.find('.DialogTitle span').text(title);
	//设置拖拽事件
	dialogObj.find('.DialogTitle').bind('mousedown',function(){
		dialog.find(".ui-dialog-titlebar").drag();
	});
	//关闭按钮
	dialogObj.find('.DialogClose').hover(function(){
		$(this).toggleClass('DialogCloseHover');
	}).unbind('click').bind('click',function(){
		dialogObj.dialog("close");}
	);
	dialogObj.find('#confirmBtn').unbind('click').bind('click',function(){
		dialogObj.dialog("close");
		if(btnFunc!=undefined&&btnFunc!=null){
			btnFunc();
		}
	});
	return dialogObj;
}


function removeOldDialogBorder(dialog){
	var moveWidth=dialog.find(".midTop").width();
	var titleObj=dialog.find(".ui-dialog-titlebar");
	titleObj.html('').attr('class','').css({
		background: "none",
		height: 33,
		position: "absolute",
		top: "20px",
		width: moveWidth,
		"min-width":"300px",
		cursor:"move",
		"z-index": 9999
	});//去掉标题栏
	dialog.find(".ui-resizable-handle").remove();//去掉标题栏
	dialog.css({"border":"0",background:"none"});
}